package com.hua.yuan.ui.data;
import com.hua.yuan.base.Constents;
import com.hua.yuan.http.Actions;
import com.hua.yuan.http.GetDataTask;
import com.hua.yuan.http.RequestPramsMap;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.Map;

import cm.hua.yuan.common.utils.PreferenceUtils;

/**
 * Created by huangyang on 2018/5/13.
 * 登录注册模块的数据请求接口
 */

public class LoginDataRequest {


    /**
     * 获取短信验证码
     *
     * @param mobile         手机号
     * @param stringCallback 返回结果
     */
    public static void getMsgCode(String mobile, StringCallback stringCallback) {

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("mobile", mobile)
                .getHashMap();

        GetDataTask.getDataPost(Actions.GET_CODE, hashMap, stringCallback);

    }


    /**
     * 用户注册
     *
     * @param mobile         手机号
     * @param password       用户的密码
     * @param sms_code       验证码
     * @param stringCallback 结果
     */
    public static void register(String mobile, String password, String sms_code, StringCallback stringCallback) {

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("mobile", mobile)
                .put("password", password)
                .put("sms_code", sms_code)
                .getHashMap();

        GetDataTask.getDataPost(Actions.USR_REGISTER, hashMap, stringCallback);

    }


    /**
     * 登录接口
     *
     * @param mobile         手机号
     * @param password       密码
     * @param stringCallback 返回的参数
     */
    public static void  login(String mobile, String password, StringCallback stringCallback) {

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("mobile", mobile)
                .put("password", password)
                .getHashMap();

        GetDataTask.getDataPost(Actions.USER_LOGIN, hashMap, stringCallback);

    }


    /**
     * 忘记密码
     * @param mobile 手机号
     * @param password 新密码
     * @param sms_code 验证码
     * @param stringCallback 结果
     */
    public static void forgetPwd(String mobile, String password, String sms_code, StringCallback stringCallback){

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("mobile", mobile)
                .put("password", password)
                .put("sms_code", sms_code)
                .getHashMap();

        GetDataTask.getDataPost(Actions.FORGET_PWD, hashMap, stringCallback);


    }


    /**
     * 修改密码
     * @param old_password 旧密码
     * @param new_password 新密码
     * @param stringCallback 结果
     */
    public static void changedPwd(String old_password, String new_password, StringCallback stringCallback){

        String token = PreferenceUtils.getString(null, Constents.TOKEN);

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("old_password", old_password)
                .put("new_password", new_password)
                .put("token", token)
                .getHashMap();

        GetDataTask.getDataPost(Actions.CHANGED_PWD, hashMap, stringCallback);
    }

    /**
     * 修改头像
     * @param head_img 头像
     * @param type 类型 后缀
     * @param stringCallback 结果
     */
    public static void changedUserHead(String head_img, String type, StringCallback stringCallback){

        String token = PreferenceUtils.getString(null, Constents.TOKEN);

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("head_img", head_img)
                .put("type", type)
                .put("token", token)
                .getHashMap();

        GetDataTask.getDataPost(Actions.CHANGED_HEAD_IMG, hashMap, stringCallback);
    }


    /**
     * 修改用户的信息
     * @param head_url 头像
     * @param mobile 手机号
     * @param nick_name 用户昵称
     * @param sex 性别，1代表男，2代表女
     * @param birthday 生日
     * @param stringCallback 结果
     */
    public static void changedUserInfo(String head_url, String mobile, String nick_name,String sex,String birthday,StringCallback stringCallback){

        String token = PreferenceUtils.getString(null, Constents.TOKEN);

        Map<String, String> hashMap = new RequestPramsMap.Builder()
                .put("head_url", head_url)
                .put("mobile", mobile)
                .put("nick_name", nick_name)
                .put("sex", sex)
                .put("birthday", birthday)
                .put("token", token)
                .getHashMap();

        GetDataTask.getDataPost(Actions.CHANGED_USER_INFO, hashMap, stringCallback);
    }




}
